--[[
parte derivada del mod dlantern en survivetest
- BY : DUCKGO LICENSE : MIT TEXTURE : CC-BY-4.0 VERSION : 0.2

author: Adaptación realizada por Oscoder.
]]--


minetest.register_node("morelanterns:dlantern", {
	description = "Lantern",
	drawtype = "mesh",
	mesh = "dlantern.obj",
	inventory_image = "morelanterns_dlantern_inv.png",
	wield_image = "morelanterns_dlantern_inv.png",
	tiles = {"morelanterns_dlantern.png"} ,
	use_texture_alpha = "clip",
	paramtype = "light",
	paramtype2 = "wallmounted",
	sunlight_propagates = true,
	light_source = LIGHT_LEVELS.low,
	groups = {cracky = 3, oddly_breakable_by_hand = 3, lantern=1},
	drop = "morelanterns:dlantern",
	selection_box = {
		type = "wallmounted",
		wall_bottom = {-0.2, -0.5, -0.2, 0.2, -0.08, 0.2},
	},
	
	sounds = default.node_sound_glass_defaults(),
	on_place = function(itemstack, placer, pointed_thing)
		local under = pointed_thing.under
		local node = minetest.get_node(under)
		local def = minetest.registered_nodes[node.name]
		if def and def.on_rightclick and
			not (placer and placer:is_player() and
			placer:get_player_control().sneak) then
			return def.on_rightclick(under, node, placer, itemstack,
				pointed_thing) or itemstack
		end

		local above = pointed_thing.above
		local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
		local fakestack = itemstack
		if wdir == 0 then
			fakestack:set_name("morelanterns:dlantern_ceiling")
		elseif wdir == 1 then
			fakestack:set_name("morelanterns:dlantern")
		else
			fakestack:set_name("morelanterns:dlantern_wall")
		end

		itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
		itemstack:set_name("morelanterns:dlantern")

		return itemstack
	end
	
})

-- Pared :
minetest.register_node("morelanterns:dlantern_wall", {
	drawtype = "mesh",
	mesh = "dlantern_wall.obj",
	--inventory_image = "dlantern_inv.png",
	--wield_image = "dlantern_inv.png",
	tiles = {"morelanterns_dlantern.png"} ,
	use_texture_alpha = "clip",
	paramtype = "light",
	paramtype2 = "wallmounted",
	sunlight_propagates = true,
	light_source = LIGHT_LEVELS.med,
	groups = {cracky = 3, oddly_breakable_by_hand = 3,not_in_creative_inventory = 1, lantern=1},
	drop = "morelanterns:dlantern",
	selection_box = {
		type = "wallmounted",
		wall_side = {-0.4, -0.199, -0.19, 0.006, 0.199, 0.19},
	},
	
	sounds = default.node_sound_glass_defaults(),
})
	


-- Techo
minetest.register_node("morelanterns:dlantern_ceiling", {
	drawtype = "mesh",
	mesh = "dlantern_ceiling.obj",
	--inventory_image = "dlantern_inv.png",
	--wield_image = "dlantern_inv.png",
	tiles = {"morelanterns_dlantern.png"} ,
	use_texture_alpha = "clip",
	paramtype = "light",
	paramtype2 = "wallmounted",
	sunlight_propagates = true,
	light_source = LIGHT_LEVELS.high,
	groups = {cracky = 3, oddly_breakable_by_hand = 3,not_in_creative_inventory = 1,lantern=1 },
	drop = "morelanterns:dlantern",
	selection_box = {
		type = "wallmounted",
		wall_top = {-0.2, -0.001, -0.2, 0.2, 0.4, 0.2},
	},
	
	sounds = default.node_sound_glass_defaults(),
})

minetest.register_lbm({
	name = "morelanterns:3dlantern",
	nodenames = {"morelanterns:dlantern", "morelanterns:dlantern_ceiling", "morelanterns:dlantern_wall"},
	action = function(pos, node)
		if node.param2 == 0 then
			minetest.set_node(pos, {name = "morelanterns:dlantern_ceiling",
				param2 = node.param2})
		elseif node.param2 == 1 then
			minetest.set_node(pos, {name = "morelanterns:dlantern",
				param2 = node.param2})
		else
			minetest.set_node(pos, {name = "morelanterns:dlantern_wall",
				param2 = node.param2})
		end
	end
})

-- receta :


minetest.register_craft({
	output = "morelanterns:dlantern",
	recipe = {
		{"", "default:steel_ingot", ""},
		{"", "default:torch", ""},
		{"", "default:glass", ""},
	}
})
	
	
	
	
	

-- Cadenas :

-- Techo
minetest.register_node("morelanterns:dlantern_chains", {
	description = "Lantern Chains",
	drawtype = "mesh",
	mesh = "chains.obj",
	inventory_image = "morelanterns_chain.png",
	wield_image = "morelanterns_chain.png",
	tiles = {"morelanterns_chains.png"} ,
	use_texture_alpha = "clip",
	paramtype = "light",
	paramtype2 = "wallmounted",
	sunlight_propagates = true,
	--light_source = 12,
	sounds = default.node_sound_metal_defaults(),
	groups = {cracky = 3, oddly_breakable_by_hand = 3, lantern=1},
	drop = "morelanterns:dlantern_chains",
	selection_box = {
		type = "wallmounted",
		wall_top = {-0.1, -0.5, -0.1, 0.1, 0.5, 0.1}, -- teto
                wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.5, 0.1}, -- chão
                wall_side = {-0.5, -0.1, -0.1, 0.5, 0.1, 0.1}, -- Parede
        }
	
})	
	
	

minetest.register_craft({
	output = "morelanterns:dlantern_chains",
	recipe = {
		{"", "default:steel_ingot", ""},
		{"", "default:steel_ingot", ""},
		{"", "default:steel_ingot", ""},
	}
})	